MODNAME=thrift
ROOT_PATH=..

BIN_PATH=$(ROOT_PATH)/bin
INCLUDE_PATH=$(ROOT_PATH)/include
LIB_PATH=$(ROOT_PATH)/lib

THRIFT=/usr/bin/env thrift

CP=/bin/cp -f
RM=/bin/rm -f
MV=/bin/mv -f
MKDIR=/bin/mkdir -p

CC=g++ -g3

INCLUDES=-I$(INCLUDE_PATH) -I/usr/local/include/thrift

THRIFTFILE1 = queue.tft
GENCXXFILE1 = ./gen-cpp/queue_constants.cpp ./gen-cpp/queue_types.cpp ./gen-cpp/Queue.cpp
THRIFTOBJ1=$(GENCXXFILE1:.cpp=.o)
TARGET1=$(ROOT_PATH)/lib/libthrift_goblin_sqs_queue.a

all: preexec $(TARGET1) afterexec

$(TARGET1): $(THRIFTOBJ1)
	ar r $(TARGET1) $(THRIFTOBJ1)
	ranlib $(TARGET1)

$(TARGET5): $(THRIFTOBJ5)
	ar r $(TARGET5) $(THRIFTOBJ5)
	ranlib $(TARGET5)

.SUFFIXES: .o .cpp
.cpp.o:
	$(CC) -c $(INCLUDES) -I ../gen-cpp $< -o $@

.PHONY: preexec
preexec:
	$(MKDIR) $(INCLUDE_PATH)/$(MODNAME)
	$(MKDIR) $(LIB_PATH)
	$(THRIFT) -o . --gen cpp $(THRIFTFILE1)
	$(CP) ./gen-cpp/*.h $(INCLUDE_PATH)/$(MODNAME)

.PHONY: afterexec
afterexec:
	$(RM) *~ *.swp

.PHONY: clean
clean:
	$(RM) *.o $(TARGET1)
	$(RM) -r $(INCLUDE_PATH)/$(MODNAME)
	$(RM) -r gen-*